#include "SingletonEhan.h"
#include <QDebug>

#include "UI/ModRun/Output/FactoryOutput.h"

//这句话放到.h文件中一直报错，会被认为是声明;
std::shared_ptr<SingletonEhan> SingletonEhan::m_pInstance(new SingletonEhan());

//私有化构造函数, 方式外部new;
SingletonEhan::SingletonEhan()
{
    //防破解;
    if (m_pInstance)
    {
        throw std::runtime_error("已经实例化，不能再创建");
    }
    QString strOutput = "单例模式:饿汉:构造";
    qDebug() << strOutput;
    std::shared_ptr<IOutput> pOutPut = FactoryOutput::GetInstance()->CreateRunOutput();
    if (pOutPut)
    {
        std::initializer_list<QString> outList{ strOutput };
        pOutPut->OutPut(outList);
    }
}

SingletonEhan::~SingletonEhan()
{
    QString strOutput = "单例模式:饿汉:析构";
    qDebug() << strOutput;
    std::shared_ptr<IOutput> pOutPut = FactoryOutput::GetInstance()->CreateRunOutput();
    if (pOutPut)
    {
        std::initializer_list<QString> outList{ strOutput };
        pOutPut->OutPut(outList);
    }
}

std::shared_ptr<SingletonEhan> SingletonEhan::GetInstance()
{
    return m_pInstance;
}

/// <summary>
/// 其他接口;
/// </summary>
void SingletonEhan::Display()
{
    QString strThis = QString::number(reinterpret_cast<quintptr>(this), 16);
    QString strOutput = "单例模式:饿汉:Display " + strThis;
    qDebug() << strOutput;
    std::shared_ptr<IOutput> pOutPut = FactoryOutput::GetInstance()->CreateRunOutput();
    if (pOutPut)
    {
        std::initializer_list<QString> outList{ strOutput };
        pOutPut->OutPut(outList);
    }
}
